#!/usr/bin/env bash
# Copyright (c) 2017 Presto Labs Pte. Ltd.
# Author: leon, inkyu

if [ -z $1 ]; then
  >&2 echo "Usage: print_config.sh [CONFIG_FILE]"
fi

CONFIG_FILE="${1}"
if [ -f "${CONFIG_FILE}" ]; then
  source "${CONFIG_FILE}"
fi

if [ -z "${PACKAGE_NAME}" -o \
     -z "${REMOTE_MACHINE_USER}" -o \
     -z "${REMOTE_MACHINE_DEPLOY_DIR}" ]; then
  >&2 echo "Configuration file miss key parameters!"
  exit 1
else
  printf "  %-25s: %s\n" "PACKAGE_NAME" "${PACKAGE_NAME}"
  printf "  %-25s: %s\n" "BAKE_BINARY" "${BAKE_BINARY[0]}"
  for _binary in "${BAKE_BINARY[@]:1}"; do
    printf "  %-25s  %s\n" " " "${_binary}"
  done
  printf "  %-25s: %s\n" "DATA_FILE" "${DATA_FILE[0]}"
  for _data in "${DATA_FILE[@]:1}"; do
    printf "  %-25s  %s\n" " " "${_data}"
  done
  printf "  %-25s: %s\n" "PYTHON_PACKAGE" "${PYTHON_PACKAGE[0]}"
  for _py in "${PYTHON_PACKAGE[@]:1}"; do
    printf "  %-25s  %s\n" " " "${_py}"
  done
  printf "  %-25s: %s\n" "REMOTE_MACHINE" "${REMOTE_MACHINE[0]}"
  for _machine in "${REMOTE_MACHINE[@]:1}"; do
    printf "  %-25s  %s\n" " " "${_machine}"
  done
  printf "  %-25s: %s\n" "REMOTE_MACHINE_USER" "${REMOTE_MACHINE_USER}"
  printf "  %-25s: %s\n" "REMOTE_MACHINE_DEPLOY_DIR" "${REMOTE_MACHINE_DEPLOY_DIR}"
  printf "  %-25s: %s\n" "REMOTE_MACHINE_RECENT_DIR" "${REMOTE_MACHINE_RECENT_DIR}"
  printf "  %-25s: %s\n" "TZ" "${TZ}"
  printf "  %-25s: %s\n" "RETENTION" "${RETENTION:-No}"
  printf "  %-25s: %s\n" "BAKE_DEPLOY_WITH_LOCAL_CHANGES" "${BAKE_DEPLOY_WITH_LOCAL_CHANGES}"
fi
